package com.lzh.cli.example;

import picocli.CommandLine;
import picocli.CommandLine.Option;

import java.util.concurrent.Callable;

/**
 * picocli交互式输入示例
 *
 * @author lzh
 * @version 1.0
 * @date 2025/3/30
 */
public class Login implements Callable<Integer> {
    @Option(names = {"-u", "--user"}, description = "User name")
    String user;

    @Option(names = {"-p", "--password"}, description = "Passphrase", interactive = true,
            arity = "0..1", prompt = "请输入密码: ", echo = true)
    String password; // interactive 交互式输入, prompt 提示语, echo 显示用户的输入, arity 可接受的参数个数

    @Option(names = {"-cp", "--checkPassword"}, description = "check Password", interactive = true, arity = "0..1")
    String checkPassword;

    public Integer call() {
        System.out.println("user = " + user);
        System.out.println("password = " + password);
        System.out.println("checkPassword = " + checkPassword);
        return 0;
    }

    public static void main(String[] args) {
        // args = new String[] {"-u", "user123", "-p", "123456", "-cp"};
        args = new String[] {"-u", "user123", "-p", "-cp"};
        new CommandLine(new Login()).execute(args);
    }

}
